package at.fhj.itm10.ticketmaster.beans;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;

import at.fhj.itm10.ticketmaster.dao.DAOException;
import at.fhj.itm10.ticketmaster.dao.DAOFactory;
import at.fhj.itm10.ticketmaster.dao.TicketDAO;
import at.fhj.itm10.ticketmaster.dao.impl.DAOFactoryImpl;
import at.fhj.itm10.ticketmaster.models.Ticket;

/**
 * @author 	Kevin Reinmueller
 * @since	November 2012
 */

@ManagedBean
@RequestScoped
public class TicketBean {

	private TicketDAO dao;
	private Ticket ticket;
	
	public TicketBean() {
		super();
		init();
	}
	
	@PostConstruct
	public void init(){
		try {
			// getDAO
			DAOFactory daoFactoryImpl;
			daoFactoryImpl = new DAOFactoryImpl();
			setDao(daoFactoryImpl.getTicketDAO());

			//insert test data
//			dao.insert(new Ticket(1, 1, 4, Calendar.getInstance().getTime()));
//			dao.insert(new Ticket(2, 2, 1, Calendar.getInstance().getTime()));
//			
//			//get test data
//			setTicket(dao.findById(12));
//			
//			//print test data to console
//			System.err.println(getTicket().toString());
		} catch (DAOException e) {
			e.printStackTrace();
		}
		
		//setTicket(new Ticket(4, 4, 5, Calendar.getInstance().getTime()));
	}

	public TicketDAO getDao() {
		return dao;
	}

	public void setDao(TicketDAO dao) {
		this.dao = dao;
	}

	public Ticket getTicket() {
		return ticket;
	}

	public void setTicket(Ticket ticket) throws DAOException {
		this.ticket = ticket;
		dao.insert(ticket);
	}

}
